package com.honey.standard.writer;

import java.util.Properties;

import org.w3c.dom.Element;

import com.honey.configureation.holder.ConfigurationHolder;
import com.honey.configureation.xmlparser.ParseElement;
import com.honey.core.NullPlugin;
import com.honey.core.compiler.StorageType;
import com.honey.core.utils.StringUtility;

/**
 * 标准存储插件
 * @author Administrator
 *
 */
public class StandardWriterPlugin extends NullPlugin implements ConfigurationHolder  {
	
	private StorageType storageType = null ;
 	 
	private String charset = null ;
	
	private boolean  enableWrite=false ;  
	
	private boolean  enableHidden=false;
	
	@Override
	public void parserElement(Element element, Properties properties) {
		String tmp =null;
		tmp =  ParseElement.getConfiguration(element, "storage", properties);
		if( "backup".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.BACKUP_STORAGE ;
		}else if( "multi".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.MULTI_STORAGE ;
		}else if( "override".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.OVERRIDE_STORAGE ;
		}else if( "checking".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_STORAGE ;
		}else if( "checkingandbackup".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_BACKUP_STORAGE ;
		}else if( "checkingbackup".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_BACKUP_STORAGE ;
		}else if( "cab".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_BACKUP_STORAGE ;
		}else if( "checkingandmulti".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_MULTI_STORAGE ;
		}else if( "checkingmulti".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_MULTI_STORAGE ;
		}else if( "cam".equalsIgnoreCase(tmp) ){
			this.storageType =StorageType.CHECKING_MULTI_STORAGE ;
		}
		
		tmp =  ParseElement.getConfiguration(element, "charset", properties);
		if(tmp != null) charset = tmp;
		
		tmp =  ParseElement.getConfiguration(element, "encoding", properties);
		if(tmp != null) charset = tmp;
		
		tmp =  ParseElement.getConfiguration(element, "enableWrite", properties);
		enableWrite = StringUtility.isTrue(tmp) ;
		
		tmp =  ParseElement.getConfiguration(element, "enableHidden", properties);
		enableHidden = StringUtility.isTrue(tmp) ;
	}

	@Override
	public String toXmlElement() {
		return null;
	}

	@Override
	public void validate() {
		
	}

	/**
	 * @return the storage
	 */
	public final StorageType getStorageType() {
		return storageType;
	}

	/**
	 * @return the charset
	 */
	public final String getCharset() {
		return charset;
	}

	/**
	 * @return the enableWrite
	 */
	public final boolean isEnableWrite() {
		return enableWrite;
	}

	/**
	 * @return the enableHidden
	 */
	public final boolean isEnableHidden() {
		return enableHidden;
	}
	
}
